package com.hengxinguotong.zhihuichengjian.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.hengxinguotong.zhihuichengjian.R;
import com.hengxinguotong.zhihuichengjian.bean.ProjectBean;
import com.hengxinguotong.zhihuichengjian.widget.font.HXTextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/8/17.
 */

public class HorizontalListViewAdapter extends BaseAdapter {

    private List<ProjectBean> list;
    private Context context;
    private LayoutInflater inflater;

    public HorizontalListViewAdapter(List<ProjectBean> list, Context context) {
        this.list = list;
        this.context = context;
        this.inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if(null == convertView ){
            convertView = inflater.inflate(R.layout.item_supervise, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder)convertView.getTag();
        }
        ProjectBean bean = list.get(position);
        holder.areaName.setText(bean.getAreaName());
        holder.warnCount.setText(bean.getCount() + "");
        if(position == 0){
            holder.areaName.setTextColor(context.getResources().getColor(R.color.color_c9222a));
            holder.warnCount.setTextColor(context.getResources().getColor(R.color.color_c9222a));
        }else if(position == 1){
            holder.areaName.setTextColor(context.getResources().getColor(R.color.color_f1636a));
            holder.warnCount.setTextColor(context.getResources().getColor(R.color.color_f1636a));
        }else if(position == 2){
            holder.areaName.setTextColor(context.getResources().getColor(R.color.color_ffc065));
            holder.warnCount.setTextColor(context.getResources().getColor(R.color.color_ffc065));
        }else{
            holder.areaName.setTextColor(context.getResources().getColor(R.color.btn_txt_gray));
            holder.warnCount.setTextColor(context.getResources().getColor(R.color.btn_txt_gray));
        }
        return convertView;
    }

    static class ViewHolder{
        @BindView(R.id.warn_count)
        HXTextView warnCount;
        @BindView(R.id.area_name)
        HXTextView areaName;

        ViewHolder(View view){
            ButterKnife.bind(this, view);
        }
    }
}
